﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace webnew.UserControls
{
    public partial class UcTitleCheckBox : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            
        }
        /// <summary>
        /// 显示职称选项
        /// </summary>
        public void ShowCheckBox()
        {
            System.Text.StringBuilder strSql = new System.Text.StringBuilder();
            strSql.Append("isdel=0 order by sort,titleName desc ");
            webnew.Common.CommonHelper.DataLbBind(chkTitle, new BLL.Sys_Title().GetconList(strSql.ToString()), "titleName", "id");
        }
        /// <summary>
        /// 显示职称选项，并选定当前用户的职称
        /// </summary>
        /// <param name="titleNameList"></param>
        public void ShowCheckBox(string titleNameList)
        {
            this.ShowCheckBox();
            string[] titleNames = titleNameList.Split(',');
            for (int i = 0; i < chkTitle.Items.Count; i++)
            {
                for (int j = 0; j < titleNames.Length; j++)
                {
                    if (chkTitle.Items[i].Text == titleNames[j].ToString())
                    {
                        chkTitle.Items[i].Selected = true;
                    }
                }
            }
            
        }
        /// <summary>
        /// 获取当前所有选定的职称
        /// </summary>
        /// <returns>返回职称数组</returns>
        public string  GetAllCheckedValue()
        {
            string strTitles = "";
            for (int i = 0; i < chkTitle.Items.Count; i++)
            {
                if (chkTitle.Items[i].Selected)
                {
                    strTitles += chkTitle.Items[i].Text.Trim() + ",";
                }
            }
            strTitles = strTitles.Length > 0 ? strTitles.Substring(0, strTitles.LastIndexOf(',')) : "";
            return strTitles;
        }
    }
}